'''
Created on 2012-8-20

@author: game-netease
'''

class Cell(object):
    def __init__(self):
        self.m_characters = [];
        
    def addSprite(self, character):
        if not character in self.m_characters:
            self.m_characters.append(character)
            
    def delSprite(self, character):
        if character in self.m_characters:
            self.m_characters.remove(character)
            
    def getSprites(self):
        return self.m_characters; 

class CellMgr(object):
    '''
    classdocs
    '''
    def __init__(self, map_size, cell_size):
        '''
        Constructor
        '''
        self.m_map_size = map_size;
        self.m_cell_size = cell_size;
        self.m_cell_count = (int(map_size[0]*1.0/cell_size[0]+0.5), int(map_size[1]*1.0/cell_size[1]+0.5))
        
        self.m_cell = []
        for j in xrange(self.m_cell_count[0]):
            self.m_cell.append([])
            for i in xrange(self.m_cell_count[1]):
                c = Cell()
                self.m_cell[j].append(c)
         
       
    def getCellByPosition(self, position):
        x = int(position[0] / self.m_cell_size[0])
        y = int(position[1] / self.m_cell_size[1])
        return self.m_cell[x][y]
          
    